#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

const int kInf = 1e9;

bool Check(int x, int y, int n, int m) {
  return x >= 0 && x < n && y >= 0 && y < m;
}

void Solve() {
  int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  vector<string> grid;
  vector<vector<int>> cost, dist, pre;
  int n, m;

  cin >> n >> m;
  grid.resize(n);
  cost.resize(n, vector<int>(m, 0));
  dist.resize(n, vector<int>(m, kInf));
  pre.resize(n, vector<int>(m, -1));
  for (int i = 0; i < n; i++) {
    cin >> grid[i];
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (grid[i][j] == '#') {
        cost[i][j] = 1;
      } else {
        cost[i][j] = 2;
        for (int k = 0; k < 4; k++) {
          if (Check(i + dir[k][0], j + dir[k][1], n, m) && grid[i + dir[k][0]][j + dir[k][1]] == '#') {
            cost[i][j] = 0;
          }
        }
      }
    }
  }

  queue<pair<int, int>> que[2];

  for (int i = 0; i < n; i++) {
    if (cost[i][0] != 0) {
      dist[i][0] = cost[i][0] - 1;
      que[dist[i][0]].emplace(i, 0);
    }
  }

  int dir2[4][2] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
  for (int d = 0; que[0].size() + que[1].size(); d++) {
    for (queue<pair<int, int>> &now = que[d & 1]; !now.empty(); now.pop()) {
      int x = now.front().first, y = now.front().second;

      if (dist[x][y] != d) {
        continue;
      }
      for (int k = 0; k < 4; k++) {
        int nx = x + dir2[k][0], ny = y + dir2[k][1];
        if (Check(nx, ny, n, m) && cost[nx][ny] != 0 && dist[nx][ny] > d + cost[nx][ny] - 1) {
          pre[nx][ny] = k;
          dist[nx][ny] = d + cost[nx][ny] - 1;
          que[dist[nx][ny] & 1].emplace(nx, ny);
        }
      }
    }
  }

  int best = 0;
  for (int i = 1; i < n; i++) {
    if (dist[i][m - 1] < dist[best][m - 1]) {
      best = i;
    }
  }
  if (dist[best][m - 1] == kInf) {
    cout << "NO\n";
  } else {
    cout << "YES\n";
    for (int nowx = best, nowy = m - 1;;) {
      grid[nowx][nowy] = '#';
      if (nowy == 0) {
        break;
      }
      int k = pre[nowx][nowy];
      nowx -= dir2[k][0];
      nowy -= dir2[k][1];
    }
    for (int i = 0; i < n; i++) {
      cout << grid[i] << "\n";
    }
  }
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int T;

  for (cin >> T; T; T--) {
    Solve();
  }
  return 0;
}